Ext.onReady(function(){
    Ext.define('SysLoginLogModel',{
        extend: 'Ext.data.Model',
        fields: [
			 {name:'login_name',type:'string'},
			 {name:'login_time',type:'string'},
			 {name:'login_ip',type:'string'},
			 {name:'company__cn_name',type:'string'},
			 {name:'employe__name',type:'string'}
        ]
    });
    //创建数据源
    var SysLoginLogStore = Ext.create('Ext.data.Store', {
    	pageSize:20,
        model: 'SysLoginLogModel',
	    proxy: {
	        type: 'ajax',
	        url: '/usercontrol/syslogin_log_list/',
	        actionMethods:'post',
	        reader: {
	            type: 'json',
	            root: 'rows',
	            totalProperty: 'totalCount'
	        }
	    }
	    //autoLoad: true
    });  

    //创建Grid
    var SysLoginLogGrid = Ext.create('Ext.grid.Panel',{
        store: SysLoginLogStore,
        loadMask:true,
        columnLines:true,
        columns: [
            Ext.create('Ext.grid.RowNumberer'),// 序列
            {text: "登录用户名", width: 100, dataIndex: 'login_name', sortable: false},
            {text: "登录时间", width: 150, dataIndex: 'login_time', sortable: false},
            {text: "登录IP", width: 150, dataIndex: 'login_ip', sortable: false},
            {text: "所属校区", width: 120, dataIndex: 'company__cn_name', sortable: false},
            {text: "关联员工", width: 120, dataIndex: 'employe__name', sortable: false}
        ],
        viewConfig: {
            stripeRows: true
        },
        dockedItems : [{
            xtype : 'pagingtoolbar',
            store : SysLoginLogStore,
            dock : 'bottom',
            displayInfo : true,
            autoScroll:true 
        },{
        	dock:'top',
        	xtype:'toolbar',
        	items:[{
        		id:'login_name',
        		//name:'login_name',
        		xtype:'textfield',
        		labelWidth: 50,
            	width: 160,
        		fieldLabel:'用户名'
        	},{
        		xtype:'datefield',
        		fieldLabel:'开始时间',
        		labelWidth: 60,
        		id:'start_day',
        		//name:'start_day',
        		editable:false,
        		format: 'Y-m-d',
        		value: new Date()
        	},{
            	xtype: 'timefield',
            	id: 'start_time',
            	//name: 'start_time',
            	width: 60,
            	minValue: '00:00',
            	maxValue: '23:59',
            	editable:false,
            	value:'00:00',
            	format:'H:i',
            	increment: 15,
            	anchor: '100%'
            },{
        		xtype:'datefield',
        		fieldLabel:'结束时间',
        		labelWidth: 60,
        		id:'end_day',
        		//name:'end_day',
        		editable:false,
        		format: 'Y-m-d',
        		value: new Date()
        	},{
            	xtype: 'timefield',
            	id: 'end_time',
            	//name: 'end_time',
            	width: 60,
            	minValue: '00:00',
            	maxValue: '23:59',
            	editable:false,
            	value:'23:59',
            	format:'H:i',
            	increment: 15,
            	anchor: '100%'
            },{
        		xtype:'button',
        		text:'查询',
        		iconCls:'search', 
        		handler:function(){
        			var params = {
        				login_name: Ext.getCmp('login_name').getValue(),
        				start_day: Ext.util.Format.dateRenderer('Y-m-d')(Ext.getCmp('start_day').getValue()),
        				start_time: Ext.util.Format.dateRenderer('H:i')(Ext.getCmp('start_time').getValue()),
        				end_day: Ext.util.Format.dateRenderer('Y-m-d')(Ext.getCmp('end_day').getValue()),
        				end_time: Ext.util.Format.dateRenderer('H:i')(Ext.getCmp('end_time').getValue())
        			};
        		    Ext.apply(SysLoginLogStore.proxy.extraParams, params);
        		    SysLoginLogStore.currentPage=1;
        		    SysLoginLogStore.load({params:{ start: 0, limit:20 }});
        		}
        	}]
        }]
    });
    

	
	Ext.create('Ext.container.Viewport',{
		layout:'fit',
		renderTo: 'sysloginlog-grid',
		items:[SysLoginLogGrid]
	});
});